#pragma once
#include "COM_h.h"
#include "Define.h"
#include <tchar.h>
#include <windows.h>

//
//  CAnimals
//

class CAnimal : public IUnknown
{
public:
    CAnimal();
    ~CAnimal();

public:
    BEGIN_INTERFACE_PART(Dog, IDog)
        virtual HRESULT STDMETHODCALLTYPE Call(void);
    END_INTERFACE_PART(Dog)

    BEGIN_INTERFACE_PART(Cat, ICat)
        virtual HRESULT STDMETHODCALLTYPE Call(void);
    END_INTERFACE_PART(Cat)

    BEGIN_INTERFACE_PART(Pig, IPig)
        virtual HRESULT STDMETHODCALLTYPE Call(void);
    END_INTERFACE_PART(Pig)

public:
    BEGIN_INTERFACE_TABLE()
        INTERFACE_TABLE_ENTRY2(IID_IDog, CAnimal, Dog)
        INTERFACE_TABLE_ENTRY2(IID_ICat, CAnimal, Cat)
        INTERFACE_TABLE_ENTRY2(IID_IPig, CAnimal, Pig)
    END_INTERFACE_TABLE()

    DECLARE_DEFAULT_INTERFACE(CAnimal)
};

//
//  CAnimalsFactory
//

class CAnimalFactory : public IClassFactory
{
private:
    unsigned int m_nLockTick;

public:
    CAnimalFactory();
    ~CAnimalFactory();

public:
    inline unsigned int GetReferences() const { return m_nLockTick; }

public:
    BEGIN_INTERFACE_TABLE()
        INTERFACE_TABLE_ENTRY(CAnimalFactory, IClassFactory)
    END_INTERFACE_TABLE()

    DECLARE_NONEW_INTERFACE();

public:
    virtual HRESULT STDMETHODCALLTYPE CreateInstance(
        IN IUnknown* pUnkOuter,
        IN REFIID riid,
        OUT void** ppvObject
    );
    virtual HRESULT STDMETHODCALLTYPE LockServer(IN BOOL fLock);

};

EXTERN_C CAnimalFactory AnimalFactory;
